use  ".\happiness_foodsecurity.dta", clear

set more off
eststo: reg l_ladder  loggdppercapita   health_exp  freedomtomakelifechoices governance  l_hunger l_inflation l_unemp d_year*  dummy1-dummy298, vce(robust)
xi:reg l_ladder  loggdppercapita  deliveryquality health_exp  freedomtomakelifechoices governance  l_hunger l_inflation l_unemp d_year*  dummy1-dummy100, vce(robust)
foreach var of varlist dummy1-dummy100{
gen t`var' = (_b[`var']/_se[`var']) 
    gen p`var' = (2 * ttail(e(df_r), abs(_b[`var']/_se[`var']))) 
	 }
xi: reg l_ladder  loggdppercapita   health_exp  freedomtomakelifechoices governance  l_hunger l_inflation l_unemp d_year*  dummy101-dummy200, vce(robust)
foreach var of varlist dummy101-dummy200{
gen t`var' = (_b[`var']/_se[`var']) 
    gen p`var' = (2 * ttail(e(df_r), abs(_b[`var']/_se[`var']))) 
	 }
xi:reg l_ladder  loggdppercapita   health_exp  freedomtomakelifechoices governance  l_hunger l_inflation l_unemp d_year*  dummy201-dummy298, vce(robust)
foreach var of varlist dummy201-dummy298{
gen t`var' = (_b[`var']/_se[`var']) 
    gen p`var' = (2 * ttail(e(df_r), abs(_b[`var']/_se[`var']))) 
	 }

	 xi:reg l_ladder  loggdppercapita   health_exp  freedomtomakelifechoices governance  l_hunger l_inflation l_unemp d_year*  dummy1-dummy298, vce(robust)
foreach var of varlist dummy1-dummy298{
gen t2`var' = (_b[`var']/_se[`var']) 
    gen p2`var' = (2 * ttail(e(df_r), abs(_b[`var']/_se[`var']))) 
	 }



set more off
eststo clear
eststo: xtreg l_ladder  loggdppercapita  deliveryquality health_exp  freedomtomakelifechoices democraticquality l_hunger l_inflation l_unemp d_year*  , fe vce(robust)
gen included_all=1 if e(sample)


***Table 3
eststo clear
eststo: xtreg l_ladder loggdppercapita governance health_exp freedomtomakelifechoices   l_hunger l_inflation  l_unemp i.year if income_level==1, fe vce(robust)
estat ic
eststo: xtreg l_ladder loggdppercapita governance  health_exp  freedomtomakelifechoices   l_hunger l_inflation l_unemp d_year* if income_level==2, fe vce(robust)
estat ic
eststo: xtreg l_ladder  loggdppercapita governance  health_exp freedomtomakelifechoices  l_hunger l_inflation l_unemp d_year* if income_level==3, fe vce(robust)
estat ic
esttab	 , star(* 0.10 ** 0.05 *** 0.01) tex label


eststo clear
***Table 7
preserve
foreach var of varlist dummy*{
cap replace `var'=. if p`var'>.2
dropmiss `var', force
}
eststo:reg l_ladder loggdppercapita governance  health_exp   l_hunger freedomtomake l_inflation l_unemp d_year*  dummy*  , vce(cluster group) 
restore 
preserve
foreach var of varlist dummy*{
cap replace `var'=. if p`var'>.3
dropmiss `var', force
}
eststo:reg l_ladder loggdppercapita governance  health_exp   l_hunger freedomtomake l_inflation l_unemp d_year*  dummy*  , vce(cluster group) 
restore
preserve
foreach var of varlist dummy*{
cap replace `var'=. if p`var'>.4
dropmiss `var', force
}
eststo:reg l_ladder loggdppercapita governance  health_exp   l_hunger freedomtomake l_inflation l_unemp d_year*  dummy*  , vce(cluster group) 
restore 

preserve
foreach var of varlist dummy*{
cap replace `var'=. if p`var'>.5
dropmiss `var', force
}
eststo:reg l_ladder loggdppercapita governance  health_exp   l_hunger freedomtomake l_inflation l_unemp d_year*  dummy*  , vce(cluster group) 
restore 

esttab	 , star(* 0.10 ** 0.05 *** 0.01) tex label



foreach var of varlist dummy*{
cap replace `var'=. if p`var'>.1
dropmiss `var', force
}

egen dummy_count=rownonmiss(dummy*)
sum dummy_count
**Table 2

eststo clear
eststo: xtreg l_ladder loggdppercapita governance health_exp freedomtomakelifechoices   l_hunger l_inflation  l_unemp i.year , fe vce(robust)
estat ic
eststo:reg l_ladder loggdppercapita governance  health_exp   l_hunger freedomtomake l_inflation l_unemp d_year*  dummy*  , vce(cluster group) 
estat ic
eststo:reg l_ladder loggdppercapita governance  health_exp   l_hunger freedomtomake l_inflation l_unemp d_year*   , vce(cluster group) 
estat ic

esttab	 , star(* 0.10 ** 0.05 *** 0.01) tex label

***Table 4
eststo clear
eststo:reg l_ladder loggdppercapita governance health_exp   l_hunger freedomtomake l_inflation l_unemp d_year*  dummy* if income_level==1 , vce(cluster group) 
estat ic
eststo:reg l_ladder loggdppercapita governance  health_exp    l_hunger freedomtomake l_inflation l_unemp d_year*  dummy* if income_level==2 , vce(cluster group) 
estat ic
eststo:reg l_ladder loggdppercapita governance health_exp    l_hunger freedomtomake l_inflation l_unemp d_year*  dummy* if income_level==3 , vce(cluster group) 
estat ic

esttab	 , star(* 0.10 ** 0.05 *** 0.01) tex label

bysort income_level year: egen mean_ladder=mean(lifeladder)
preserve
duplicates drop income_level year, force
*Figure 1
twoway (tsline mean_ladder if income_level==1)  (tsline mean_ladder if income_level==2)  (tsline mean_ladder  if income_level==3) if year>2005
restore

***Table 4

eststo clear
eststo: reg l_ladder loggdppercapita governance freedomtomakelifechoices  health_exp    l_inflation l_hunger  l_unemp  d_year* dummy* if regioncode_27==2000, vce(cluster group) 
eststo: reg l_ladder loggdppercapita governance freedomtomakelifechoices  health_exp     l_inflation l_hunger  l_unemp  d_year* dummy* if regioncode_27==3000, vce(cluster group) 
eststo: reg l_ladder loggdppercapita governance freedomtomakelifechoices  health_exp    l_inflation l_hunger  l_unemp  d_year* dummy* if regioncode_27==4000, vce(cluster group) 

esttab	 , star(* 0.10 ** 0.05 *** 0.01) tex label

***Table 5

eststo clear
eststo: reg l_ladder loggdppercapita governance freedomtomakelifechoices  health_exp    l_inflation l_hunger   l_unemp  d_year* dummy* if lifd==1, vce(cluster group) 
eststo: reg l_ladder loggdppercapita governance freedomtomakelifechoices  health_exp    l_inflation l_hunger   l_unemp  d_year* dummy* if netfoodimport==1, vce(cluster group) 
eststo: reg l_ladder loggdppercapita  governance freedomtomakelifechoices  health_exp     l_inflation l_hunger   l_unemp  d_year* dummy* if high_depend_agri_merge==1, vce(cluster group) 
eststo: reg l_ladder loggdppercapita governance freedomtomakelifechoices  health_exp    l_inflation l_hunger   l_unemp  d_year* dummy* if  sev_drought_foodsec_merge==1, vce(cluster group) 

esttab	 , star(* 0.10 ** 0.05 *** 0.01) tex label
